package com.dlwx.parttimetalent.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;

import com.dlwx.parttimetalent.comm.Constant;
import com.dlwx.parttimetalent.ui.ChatActivity;
import com.hyphenate.easeui.EaseConstant;
import com.tbruyelle.rxpermissions2.RxPermissions;

import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2017/12/29.
 */

public class ToChatUtil {

    public static void chat(final Activity activity, final String id, final String headUrl, final String chatName){
        RxPermissions rxPermissions = new RxPermissions(activity);
        int userId = (int) SPUtils.get(activity, Constant.USER_ID, 0);
//        if(userId!=0){
//            HxUtils.login(userId+"");
//        };
        rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.CAMERA,Manifest.permission.RECORD_AUDIO,Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        if(aBoolean){
                            Intent intent=new Intent(activity,ChatActivity.class);
                            intent.putExtra(EaseConstant.EXTRA_USER_ID,id);
                            intent.putExtra("to_headportrait", headUrl);
                            intent.putExtra("to_username", chatName);
                            intent.putExtra("to_user_id", id);
                            activity.startActivity(intent);
                        }
                    }
                });
    }
}
